package com.tom.de;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

public class IPService {

    /**
     * 请求map
     */
    private static final ConcurrentHashMap<String,Integer> mp =new ConcurrentHashMap<>() ;
    public void record(HttpServletRequest request){
        //ip
        String ip = request.getLocalAddr();
        //count
        Integer i = mp.get(ip);
        i = Objects.isNull(i)?1:++i;
        //update
        mp.put(ip,i);
        //output
        mp.forEach((key,val) -> System.out.println("ip: " +key+ "  count: " +val));

    }

}
